package cn.edu.nuc.ssm.dao;

import cn.edu.nuc.ssm.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CategoryMapper {
    @Delete({
        "delete from category",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into category (id, name, ",
        "category_belong, pid)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{categoryBelong,jdbcType=INTEGER}, #{pid,jdbcType=INTEGER})"
    })
    int insert(Category record);

    int insertSelective(Category record);

    @Select({
        "select",
        "id, name, category_belong, pid",
        "from category",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("cn.edu.nuc.ssm.dao.CategoryMapper.BaseResultMap")
    Category selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Category record);

    @Update({
        "update category",
        "set name = #{name,jdbcType=VARCHAR},",
          "category_belong = #{categoryBelong,jdbcType=INTEGER},",
          "pid = #{pid,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Category record);

    @Update({
        "update category",
        "set name = #{name,jdbcType=VARCHAR}",
        "where id= #{id,jdbcType=INTEGER}"
    })
    int updateNameById(@Param("name") String name,@Param("id") Integer id);

    List<Category> findbyCategoryBelongAndUidIsNULL(@Param("categoryBelong") Integer categoryBelong);

    List<Category> findbyCategoryBelongAndUid(@Param("categoryBelong") Integer categoryBelong, @Param("uid") Integer uid);

    Category findbyId(@Param("id") Integer id);


    List<Category> findSimiler();

    int updatenamebyId(@Param("updatedName")String updatedName,@Param("id")Integer id);

    List<Category> findbyName(@Param("name")String name);


    int deletebyId(@Param("id")Integer id);




}